# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=aiohttp
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.7.1
pkgrel=1
pkgdesc='HTTP client/server for asyncio (mingw-w64)'
arch=('any')
url="https://aiohttp.readthedocs.io/"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python-async-timeout" "${MINGW_PACKAGE_PREFIX}-python-attrs" "${MINGW_PACKAGE_PREFIX}-python-chardet" "${MINGW_PACKAGE_PREFIX}-python-yarl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-cython")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-freezegun" "${MINGW_PACKAGE_PREFIX}-python-pytest-runner" "${MINGW_PACKAGE_PREFIX}-python-pytest-cov" "${MINGW_PACKAGE_PREFIX}-python-pytest-forked" "${MINGW_PACKAGE_PREFIX}-python-pytest-mock" "${MINGW_PACKAGE_PREFIX}-python-pytest-timeout" "${MINGW_PACKAGE_PREFIX}-python-pytest-xdist")
source=("https://github.com/aio-libs/aiohttp/archive/v$pkgver.tar.gz")
sha256sums=('6075f4fb46cfb73f9282709272ec4755967668c633b6276433f4bad5b6db1b2b')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-$pkgver" "python-build-${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  sed 's|.install-cython ||' -i Makefile
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  make cythonize
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py test || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
